const controller = require('./index')
const service = require('../service/FileSlice')

//  检查chunk
exports.checkChunk = (req, res) => {
  const data = service.checkChunk(req.query.fileName)
  res.send(controller.successParams({data}))
}

//  上传切片
exports.uploadChunk = (req, res) => {
  const file = req.file
  const result = service.uploadChunk(file)
  res.send(
      result
      ? controller.successParams({ data: file.originalname })
      : controller.errorParams({ msg: '上传失败' })
  )
}

//  合并切片
exports.mergeChunk = (req, res) => {
  service.mergeChunk(req).then(data => {
    res.send(controller.successParams({ data }))
  }).catch(err => {
    res.send(controller.errorParams({ msg: err || '合并失败！' }))
  })
}
